package com.yzjs.common.base.service;

import com.yzjs.localhost.entity.tAttributeFieldTranslation.TAttributeFieldTranslationEntity;
import com.yzjs.localhost.entity.tNeusoftSysMenu.TNeusoftSysMenuEntity;
import com.yzjs.localhost.service.AnalysisService;
import com.yzjs.localhost.service.tAttributeFieldTranslation.TAttributeFieldTranslationService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class SearchReceive implements ApplicationListener<ContextRefreshedEvent> {


    @Autowired
    private TAttributeFieldTranslationService  attributeFieldTranslationService ;

      @Override
      public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
          if (contextRefreshedEvent.getApplicationContext().getParent() == null) {//保证只执行一次
                         //需要执行的方法
              initFieldTranslation();

          }
      }



      public void initFieldTranslation(){
          TAttributeFieldTranslationEntity tAttributeFieldTranslation = new TAttributeFieldTranslationEntity();
          List<TAttributeFieldTranslationEntity> tAttributeFieldTranslations = attributeFieldTranslationService.findList(tAttributeFieldTranslation);
          Map<String,String> fieldTranslationMap = tAttributeFieldTranslations.stream().collect(Collectors.toMap(TAttributeFieldTranslationEntity::getFieldName, TAttributeFieldTranslationEntity::getFieldDesc));
          AnalysisService.translationMap = fieldTranslationMap;
      }
  }
